<?php

class GL_Index extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
        $data['layout_count'] = $this->product->count_pending();
        $data['layout_pending'] = $this->product->get_all_pending();
        $this->layout->setLayout("admin/layout", $data);
        if ($this->permission() != 0) redirect('../');
    }

    public function index()
    {
        $year = date('Y');
        $data['count_author'] = $this->user->count_author();
        $data['count_product'] = $this->product->count_all();
        $data['count_today_profit'] = $this->purchasing->count_today_profit() * 0.3;
        $data['count_month_profit'] = $this->purchasing->count_month_profit() * 0.3;
        $data['count_year_profit'] = $this->purchasing->count_year_profit() * 0.3;
        $data['count_profit'] = $this->purchasing->count_profit() * 0.3;
        $data['income'] = "";
        for ($i = 1; $i < 13; $i++) {
            if ($this->purchasing->get_month_profit($i, $year)['sum(purchasing_price)']) {
                $income = $this->purchasing->get_month_profit($i, $year)['sum(purchasing_price)']*0.3;
            } else $income = 0;
            $data['income'] .= $income . ",";
        }

        $data['income'] = substr($data['income'], 0, strlen($data['income']) - 1);
        $this->layout->view("admin/index", $data);
    }
}
